﻿namespace EyeOpen.Validation
{
	using System;
	using System.Linq;

	public class CsvValidator
	{
		/// <exception cref="InvalidOperationException">Minium property must be greater than 0.</exception>
		public bool Validate(string value, int minimum)
		{
			if (minimum <= 0)
			{
				throw new InvalidOperationException("Minium property must be greater than 0.");
			}

			var minimumComma =
				value
					.Count(c => c == ',') >= minimum - 1;

			return
				minimumComma && char.IsLetterOrDigit(value.Last());
		}
	}
}